#include"DList.h"

ListNode* BuyListNode(LTDataType x)
{
	ListNode* newnode = (ListNode*)malloc(sizeof(ListNode));
	if (newnode == NULL)
	{
		perror("error");
		exit(-1);
	}
	else
	{
		newnode->val = x;
		newnode->prev = NULL;
		newnode->next = NULL;
		return newnode;
	}


}

ListNode* ListCreate()
{
	ListNode* newnode = BuyListNode(-1);

	newnode->prev = newnode;
	newnode->next = newnode;

	return newnode;
	
}

void ListPushBack(ListNode* pHead, LTDataType x)
{
	assert(pHead);

	ListNode* newnode = BuyListNode(x);
	ListNode* tail = pHead->prev;
	newnode->next = pHead;
	newnode->prev = tail;
	tail->next = newnode;
	pHead->prev = newnode;

}

void ListPrint(ListNode* pHead)
{
	assert(pHead);
	ListNode* cur = pHead->next;
	printf("guide<=>");
	while (cur!=pHead)
	{
		printf("%d", cur->val);
		cur = cur->next;
	}
	printf("\n");


}